package GetTopic;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;

public class GetHtmlStringThread extends Thread{

	public String url;
	public HtmlStringClass hsc;
	
	public GetHtmlStringThread(String url,HtmlStringClass hsc){
		this.url = url;
		this.hsc = hsc;
		
	}
	public void run(){
		try{
			HttpClient c = new HttpClient();
			
			GetMethod g = new GetMethod(url);
			//System.out.println("http://www.google.com.hk/search?hl=zh-CN&q="+URLEncoder.encode(str,"utf-8"));
			
			int status = c.executeMethod(g);
			String line=null;
	        StringBuffer content = new StringBuffer();
	        
	        try{
	        	InputStream   responseBody   =   g.getResponseBodyAsStream(); 
	        	BufferedReader   in   =   new   BufferedReader(new   InputStreamReader(responseBody));
	        	while((line=in.readLine())!=null){
	        		content.append(line);
				}
				in.close(); 
			}catch (IOException e){
				e.printStackTrace();
			}
			
	        String s=content.toString();
	        
	        hsc.htmlstring = s;
	        //System.out.println(s);
		}catch(Exception e){
			
		}
       
	}
}
